package com.lzx.adx.report.util;

import org.apache.commons.lang3.StringUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public class URLEncoderDecoderTool {


    public static String encodeURL(String url) {
        if(StringUtils.isBlank(url)){
            return "";
        }
        try {
            return URLEncoder.encode(url, StandardCharsets.UTF_8.toString());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String decodeURL(String url) {
        if(StringUtils.isBlank(url)){
            return "";
        }
        try {
            return URLDecoder.decode(url, StandardCharsets.UTF_8.toString());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }





    public static void main(String[] args) {
        String originalUrl = "https://unet.quark.cn/v3/ad/cyqg_dsp?type=click&ch=kk@cpa_dsp_cyqgkklxdsp_1&targetPkg=com.quark.browser&creativeld=&os=android&campaignld=&ip=113.118.101.60&imei=&callbackUrl=https%253A%252F%252Focpxapi.weijingrui.com%252Faqy%252Fkk%252Fcallback%253FrequestId%253Db7a164b97d674be2aa0b50125b8caa9a&time=1705394909&ua=PJG110&adGroupld=&imeiSum=&oaid=465C4BC2F35A4E10868C3A5A37E49D76cde6c8a8d7ef54cb7a8280f36f538faf&oaidSum=";
//        String encodedUrl = encodeURL(originalUrl);
//        System.out.println("Encoded URL: " + encodedUrl);

        String decodedUrl = decodeURL(originalUrl);
        System.out.println("Decoded URL: " + decodedUrl);
    }
}
